package com.fstech.whiteboadrd.widget;

import android.app.Activity;
import android.content.Intent;
import android.graphics.Bitmap;
import android.net.Uri;
import android.util.Log;

import java.util.HashMap;

import cn.sharesdk.framework.Platform;
import cn.sharesdk.framework.PlatformActionListener;
import cn.sharesdk.framework.ShareSDK;
import cn.sharesdk.system.email.Email;
import cn.sharesdk.wechat.friends.Wechat;

public class ShareWidget {

    private static Platform.ShareParams getParams(String path) {
        Log.e("yx", path);
        Platform.ShareParams shareParams = new Platform.ShareParams();
        shareParams.setTitle("电子白板分享");
        shareParams.setText("电子白板分享");
//        shareParams.setShareType(Platform.SHARE_IMAGE);
        shareParams.setShareType(Platform.SHARE_FILE);
        shareParams.setFilePath(path);
//        shareParams.setImageData(image);
        shareParams.setImagePath(path);
        return shareParams;
    }

    public static void share(int platform, String path) {
        Platform wchat = ShareSDK.getPlatform(Email.NAME);
        switch (platform) {
            case 1:
                wchat = ShareSDK.getPlatform(Wechat.NAME);
                break;
            case 2:
                wchat = ShareSDK.getPlatform(Email.NAME);
                break;
        }
        wchat.setPlatformActionListener(new PlatformActionListener() {
            @Override
            public void onComplete(Platform platform, int i, HashMap<String, Object> hashMap) {

            }

            @Override
            public void onError(Platform platform, int i, Throwable throwable) {

            }

            @Override
            public void onCancel(Platform platform, int i) {

            }
        });
        wchat.share(getParams(path));
    }


    public static void sendEmail(Activity activity, String path) {
        Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);
//        emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL, emailaddress);
        emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, "电子白板分享");
//        emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, subject);
        emailIntent.setType("application/image");
        Uri uri = Uri.parse("file://" + path);
        emailIntent.putExtra(Intent.EXTRA_STREAM, uri);
        activity.startActivity(emailIntent);
    }

}
